package tests;

import listeners.OSFilter;
import listeners.OSNames;
import listeners.ProgressTracker;

import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

@Listeners({ OSFilter.class, ProgressTracker.class })
public class SampleTest {

	@Test(groups = { OSNames.OS_LINUX })
	public void test1() {
		sleep(5000);
		System.out.println(">>>test1");
	}

	@Test(groups = { OSNames.OS_LINUX, OSNames.OS_WINDOWS })
	public void test2() {
		sleep(3000);
		System.out.println(">>>test2");
	}

	@Test(groups = { OSNames.OS_LINUX, OSNames.OS_WINDOWS })
	public void test3() {
		sleep(2000);
		System.out.println(">>>test3");
	}

	@Test(groups = { OSNames.OS_WINDOWS })
	public void test4() {
		sleep(5000);
		System.out.println(">>>test4");
	}

	@Test(groups = { OSNames.OS_WINDOWS })
	public void test5() {
		sleep(5000);
		System.out.println(">>>test5");
	}

	private void sleep(long time) {
		try {
			Thread.sleep(time);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}




public static Class[] scan(ServletContext context)
{
    String root = context.getReadPath();
    ClassScanner scanner = new ClassScanner(new File(root));
    scanner.setClassLoader(ClassScanner.class.getClassLoader());
    final File testDir = new File(root, "com/foo/tests");
    scanner.setFilter(new FileFilter() {
        public boolean accept(File pathname) {
            return pathname.getPath().startsWith(testDir.getPath());
        }    
    });
    Class[] classes = scanner.getClasses();
    return classes;
}



